package com.ttuproject.ttu.service.serviceImpl;

import com.ttuproject.ttu.exception.Advice;
import com.ttuproject.ttu.exception.TTUException;
import com.ttuproject.ttu.mapper.TTUMapper.LinkageMapper;
import com.ttuproject.ttu.service.LinkageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @ClassName LinkageServiceImpl
 * @Description TODO
 * @Author cw
 * @Date 2021/12/3 10:41
 */
@Service
public class LinkageServiceImpl implements LinkageService {

    @Autowired
    LinkageMapper linkageMapper;

    @Override
    public Set<String> linkage1() {
        Set<String> linkage1 = linkageMapper.selectlinkage1();
        if (linkage1.isEmpty()) {
            throw new TTUException(Advice.LINKAGE_ERROR_1);
        } else {
            return linkage1;
        }
    }

    @Override
    public Set<String> linkage2(String linkage1) {
       Set<String> linkage2 = linkageMapper.selectlinkage2(linkage1);
        if (linkage2.isEmpty()) {
            throw new TTUException(Advice.LINKAGE_ERROR_2);
        } else {
            return linkage2;
        }
    }

    @Override
    public Set<String> linkage3(String linkage1, String linkage2) {
        Set<String> linkage3 = linkageMapper.selectlinkage3(linkage1,linkage2);
        if (linkage3.isEmpty()) {
            throw new TTUException(Advice.LINKAGE_ERROR_3);
        } else {
            return linkage3;
        }
    }

    @Override
    public Set<String> selectFaultcode() {
        Set<String> faultcodes=linkageMapper.selectFaultcode();
        if (faultcodes.isEmpty()) {
            throw new TTUException(Advice.FAULT_CODE_ERROR);
        } else {
            return faultcodes;
        }
    }

    @Override
    public String selectFailurecause(String faultcode) {
        String failurecause=linkageMapper.selectFailurecause(faultcode);
        if (StringUtils.isEmpty(failurecause)) {
            throw new TTUException(Advice.FAILURE_CAUSE_ERROR);
        } else {
            return failurecause;
        }
    }

    @Override
    public String queryGPS(String linkage1, String linkage2, String linkage3) {
       String GPS = linkageMapper.queryGPS(linkage1, linkage2, linkage3);
        if (GPS.isEmpty()) {
            throw new TTUException(Advice.QUERY_GPS_ERROR);
        } else {
            return GPS;
        }
    }


}
